//
//  MineHeaderView.m
//  HAHAWENWAN
//
//  Created by xiaowu on 2017/9/11.
//  Copyright © 2017年 ZDQK. All rights reserved.
//

#import "MineHeaderView.h"
#import <Masonry/Masonry.h>

@implementation MineHeaderView

- (instancetype)init {
    self = [super init];
    if (self) {
        [self configureUI];
    }
    return self;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    
    [self configureUI];
}


- (void)configureUI {
    self.view = [[[NSBundle mainBundle] loadNibNamed:@"MineHeaderView" owner:self options:nil] firstObject];
    self.view.frame = self.bounds;
    [self addSubview:self.view];
    
    self.headerBackView.backgroundColor = [UIColor backgroundColor];
    self.headerBackView.layer.cornerRadius = self.headerBackView.height * 0.5;
    self.headerBackView.clipsToBounds = YES;
    self.headerImageView.layer.borderColor = [UIColor whiteColor].CGColor;
    self.headerImageView.layer.borderWidth = 2;
    self.headerImageView.layer.cornerRadius = self.headerImageView.height * 0.5;
    [self.headerImageView setImage:[UIImage imageNamed:@"head_portrait"]];
}

- (IBAction)infoButtonClick:(id)sender {
    if (self.infoBlock) {
        self.infoBlock();
    }
}
- (IBAction)firstButtonClick:(id)sender {
    if (self.block) {
        self.block(0);
    }
}
- (IBAction)secondButtonClick:(id)sender {
    if (self.block) {
        self.block(1);
    }
}
- (IBAction)thirdButtonClick:(id)sender {
    if (self.block) {
        self.block(2);
    }
}
- (IBAction)fourthButtonClick:(id)sender {
    if (self.block) {
        self.block(3);
    }
}
- (IBAction)fifthButtonClick:(id)sender {
    if (self.block) {
        self.block(4);
    }
}

- (void)updateOrderCount:(OrderStatusModel *)model {
    [self setRedPointText:model.status0 Label:self.obligationLabel];
    [self setRedPointText:model.status2 Label:self.receivedLabel];
    [self setRedPointText:model.status3 Label:self.evaluationLabel];
    [self setRedPointText:model.status8 Label:self.refundedLabel];
}
- (void)setRedPointText:(NSString *)text Label:(UILabel *)redLabel{
    
    if (TextIsNotNil(text) && ![text isEqualToString:@"0"]) {
        [redLabel setHidden:NO];
        if (text.integerValue > 99) {
            text = @" 99+ ";
        }
        
        [redLabel setText:text];
        [redLabel sizeToFit];
        [redLabel setHeight:15];
        [redLabel setHalfCircleWithColor:[UIColor clearColor]];
        
        CGFloat redW = redLabel.width;
        if (redW <= 15) {
            [redLabel setWidth:15];
        }
    } else {
        [redLabel setHidden:YES];
    }
}

@end
